/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ca.barrenechea.stickyheaders.page;

import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.app.Context;

import java.util.List;

import ca.barrenechea.stickyheaders.ResourceTable;
import ca.barrenechea.stickyheaders.adapter.InlineDoubleHeaderTestAdapter;
import ca.barrenechea.widget.recyclerview.decoration.HeaderDecor;
import ca.barrenechea.widget.recyclerview.decoration.Utils;
import ca.barrenechea.widget.recyclerview.decoration.model.ItemModel;

/**
 * 显示Double Item header页面
 *
 * @since 2021-04-14
 */
public class InlineDoubleHeaderPage extends BasePage {
    private Context context;
    private InlineDoubleHeaderTestAdapter adapter;

    /**
     * 构造函数
     *
     * @param context 上下文
     */
    public InlineDoubleHeaderPage(Context context) {
        this.context = context;
    }

    @Override
    void notifyDataChange() {
        if (adapter != null) {
            adapter.notifyDataChanged();
        }
    }

    /**
     * 页面控件初始化
     *
     * @param rootView 根布局
     */
    public void init(Component rootView) {
        Text headerText = (Text) rootView.findComponentById(ResourceTable.Id_title_text);
        Text doubleText = (Text) rootView.findComponentById(ResourceTable.Id_title_double_text);
        ListContainer listContainer = (ListContainer) rootView.findComponentById(ResourceTable.Id_list_double_inline);
        List<ItemModel> dataList = Utils.getDoubleInlineList();
        adapter = new InlineDoubleHeaderTestAdapter(context, dataList);
        listContainer.setItemProvider(adapter);
        HeaderDecor headerDecor = new HeaderDecor(listContainer, headerText, doubleText);
        headerDecor.setDataList(dataList);
    }
}
